package spring.mybatis.dao;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.calvin.study.MapperFactoryBean;
import com.calvin.study.OrderFactoryBean;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:spring/spring-mybatis02.xml")
public class MyBatisTest02 {
	@Autowired
	private ApplicationContext context;
	
	/**
	 *    示例：
	 *    1.FactoryBean接口的Bean，在调用getObject方法后，返回object对象实例。
	 *    2.在容器中以“&”开头获取的FactoryBean，即为该Bean本身实例
	 * 
	 */
	@Test
	public void test02() {
		try {
			OrderFactoryBean bean1 = context.getBean(OrderFactoryBean.class);
			System.out.println("bean1 : " + bean1.getObject());
			
			OrderFactoryBean bean2 = (OrderFactoryBean) context.getBean("&orderFactoryBean");
			System.out.println("bean2 : " + bean2);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	@Test
	public void test03() {
		try {
			MapperFactoryBean bean1 = context.getBean(MapperFactoryBean.class);
			System.out.println("bean1 : " + bean1.getObject());
			
			MapperFactoryBean bean2 = (MapperFactoryBean) context.getBean("&mapperFactoryBean");
			System.out.println("bean2 : " + bean2);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
